/*     */ package com.iris.egrant.grid.utils;
/*     */ 
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ import com.iris.egrant.utils.ConditionContainer;
import com.iris.egrant.web.struts2.Struts2Utils;
import org.apache.commons.lang.ObjectUtils;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.commons.lang.math.NumberUtils;
/*     */ import org.dom4j.Document;
/*     */ import org.dom4j.DocumentHelper;
/*     */ import org.dom4j.Element;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PageHanlder
/*     */ {
/*     */   private final PageContainer page;
/*     */   private ConditionContainer conditionContainer;
/*  29 */   private Boolean directReturn = Boolean.valueOf(true);
/*     */   
/*     */   public PageHanlder() {
/*  32 */     this.page = new PageContainer();
/*  33 */     this.conditionContainer = new ConditionContainer();
/*  34 */     webInitialize();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void setDirectReturn(Boolean directReturn) {
/*  44 */     this.directReturn = directReturn;
/*     */   }
/*     */   
/*     */   public PageContainer getPage() {
/*  48 */     return this.page;
/*     */   }
/*     */   
/*     */   public void setPage(PageContainer page) {
/*  52 */     this.page.setGrid(page.getGrid());
/*  53 */     this.page.setTotalCount(page.getTotalCount());
/*  54 */     this.page.setTotalPages();
/*     */   }
/*     */   
/*     */   public ConditionContainer getConditionContainer() {
/*  58 */     return this.conditionContainer;
/*     */   }
/*     */   
/*     */   public void setConditionContainer(ConditionContainer conditionContainer) {
/*  62 */     this.conditionContainer = conditionContainer;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private final void webInitialize() {
/*  69 */     if (Struts2Utils.getParameter("page") != null) {
/*  70 */       this.page.setCurrentPage(Integer.valueOf(NumberUtils.toInt(Struts2Utils.getParameter("page"))));
/*     */     } else {
/*  72 */       this.page.setCurrentPage(Integer.valueOf(1));
/*     */     } 
/*  74 */     if (Struts2Utils.getParameter("rows") != null) {
/*  75 */       this.page.setPageRowCount(Integer.valueOf(NumberUtils.toInt(Struts2Utils.getParameter("rows"))));
/*     */     } else {
/*  77 */       this.page.setPageRowCount(Integer.valueOf(10));
/*     */     } 
/*  79 */     this.conditionContainer.setConditions(deCompostCondition());
/*  80 */     this.conditionContainer.setPageRowCount(this.page.getPageRowCount());
/*  81 */     this.conditionContainer.setCurrentPage(this.page.getCurrentPage());
/*  82 */     this.conditionContainer.setSortType(Struts2Utils.getParameter("sord"));
/*  83 */     this.conditionContainer.setSortItem(Struts2Utils.getParameter("sidx"));
/*  84 */     this.conditionContainer.setPrintToExcel(Struts2Utils.getParameter("printToExcel"));
/*  85 */     if (StringUtils.isNotBlank(this.conditionContainer.getPrintToExcel())) {
/*  86 */       this.conditionContainer.setMaxIndex(null);
/*  87 */       this.conditionContainer.setStartIndex(null);
/*     */     } else {
/*  89 */       this.conditionContainer.setStartIndex(Integer.valueOf((this.page.getCurrentPage().intValue() - 1) * this.page.getPageRowCount().intValue()));
/*  90 */       this.conditionContainer.setMaxIndex(Integer.valueOf(this.conditionContainer.getStartIndex().intValue() + this.page.getPageRowCount().intValue()));
/*  91 */       if (this.page.getPageRowCount().intValue() == 0) {
/*  92 */         this.conditionContainer.setMaxIndex(Integer.valueOf(0));
/*     */       }
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private final Map<String, Object> deCompostCondition() {
/* 104 */     Map<String, Object> conditions = new HashMap<String, Object>();
/* 105 */     String originalstr = Struts2Utils.getParameter("searchString");
/* 106 */     if (StringUtils.isBlank(originalstr)) {
/* 107 */       return conditions;
/*     */     }
/* 109 */     String[] originals = StringUtils.splitByWholeSeparator(originalstr, "[tear]");
/* 110 */     for (String originalKV : originals) {
/* 111 */       String[] originalkv = StringUtils.split(originalKV, ":", 2);
/* 112 */       String dealWithK = originalkv[0];
/* 113 */       String dealWithV = "";
/* 114 */       if (originalkv.length == 2) {
/* 115 */         dealWithV = originalkv[1];
/*     */       }
/* 117 */       conditions.put(dealWithK, dealWithV);
/*     */     } 
/* 119 */     return conditions;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private Document buildGeneral() {
/* 128 */     Document document = DocumentHelper.createDocument();
/* 129 */     Element root = document.addElement("rows");
/* 130 */     Element pageE = root.addElement("page");
/* 131 */     Element totalE = root.addElement("total");
/* 132 */     Element recordsE = root.addElement("records");
/* 133 */     pageE.setText(this.page.getCurrentPage().toString());
/* 134 */     totalE.setText(this.page.getTotalPages().toString());
/* 135 */     recordsE.setText(this.page.getTotalCount().toString());
/* 136 */     Iterator<Element> itE = root.elementIterator();
/* 137 */     StringBuilder summary = new StringBuilder();
/* 138 */     while (itE.hasNext()) {
/* 139 */       summary.append(((Element)itE.next()).asXML());
/*     */     }
/* 141 */     this.page.getGrid().setSummary(summary);
/* 142 */     return document;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void outPut() {
/* 151 */     Document gridDom = buildGeneral();
/* 152 */     if (!this.directReturn.booleanValue()) {
/* 153 */       Struts2Utils.getRequest().setAttribute("page", this.page);
/*     */     } else {
/* 155 */       Element root = gridDom.getRootElement();
/* 156 */       Iterator<Map<String, Object>> dataIt = this.page.getGrid().getData().iterator();
/* 157 */       while (dataIt.hasNext()) {
/* 158 */         int i = 0;
/* 159 */         HashMap<String, Object> datamap = (HashMap<String, Object>)dataIt.next();
/* 160 */         Element element = root.addElement("row");
/* 161 */         element.addAttribute("id", ObjectUtils.toString(datamap.get((new Integer(i)).toString())));
/* 162 */         i++;
/* 163 */         int len = datamap.size();
/* 164 */         while (i < len) {
/* 165 */           Element cell = element.addElement("cell");
/* 166 */           cell.setText(ObjectUtils.toString(datamap.get((new Integer(i)).toString())));
/* 167 */           i++;
/*     */         } 
/*     */       } 
/* 170 */       Struts2Utils.renderXml(gridDom.getRootElement().asXML(), new String[0]);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception {}
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\gri\\utils\PageHanlder.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */